<%@page import="com.module.admin.prj.enums.PrjMonitorMonitorStatus"%>
<%@page import="com.module.admin.prj.enums.PrjClientStatus"%>
<%@page import="com.module.admin.prj.enums.PrjInfoContainer"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/inc/sys.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${projectName}-编辑服务</title>
<jsp:include page="/WEB-INF/view/inc/css.jsp"></jsp:include>
</head>
<body>
	<jsp:include page="/WEB-INF/view/inc/header.jsp"></jsp:include>
	<div class="container">
		<jsp:include page="/WEB-INF/view/admin/comm/left.jsp">
			<jsp:param name="first" value="prj"/>
			<jsp:param name="second" value="prjInfoManager"/>
		</jsp:include>
		<div class="c-right">
			<div class="${bodyMainClass}">
				<div class="panel-heading panel-heading-tool">
					<div class="row">
						<div class="col-sm-5 title">服务管理 / <b>服务列表-(${prjInfo.name})</b></div>
						<div class="col-sm-7 text-right">
							<div class="btn-group">
						  		<a href="${webroot}/prjInfo/f-view/manager" class="btn btn-default btn-sm">返回</a>
						  		<a href="javascript:location.reload()" class="btn btn-default btn-sm">刷新</a>
							</div>
						</div>
					</div>
				</div>
				<div class="panel-body">
					<ul class="nav nav-tabs">
				    	<li <c:if test="${param.tab==null || param.tab=='prj'}"> class="active"</c:if>><a href="#prjPanel" data-toggle="tab">服务详情</a></li>
				    	<li <c:if test="${param.tab=='config'}"> class="active"</c:if>><a href="#configPanel" onclick="configInfo.init()" data-toggle="tab">配置文件</a></li>
				    	<li <c:if test="${param.tab=='api'}"> class="active"</c:if>><a href="#apiPanel" onclick="apiInfo.init()" data-toggle="tab">API列表</a></li>
				    	<li <c:if test="${param.tab=='version'}"> class="active"</c:if>><a href="#versionPanel" onclick="versionInfo.init()" data-toggle="tab">版本管理</a></li>
				    	<li <c:if test="${param.tab=='monitor'}"> class="active"</c:if>><a href="#monitorPanel" onclick="monitorInfo.init()" data-toggle="tab">服务监控</a></li>
				    	<li <c:if test="${param.tab=='cache'}"> class="active"</c:if>><a href="#cachePanel" onclick="cacheInfo.init()" data-toggle="tab">缓存管理</a></li>
				    	<li <c:if test="${param.tab=='code'}"> class="active"</c:if>><a href="#codePanel" onclick="codeInfo.init()" data-toggle="tab">生成源码</a></li>
				    	<li <c:if test="${param.tab=='ds'}"> class="active"</c:if>><a href="#dsPanel" onclick="dsInfo.init()" data-toggle="tab">数据源</a></li>
				  	</ul>
				  	<div class="tab-content">
					  	<input type="hidden" id="prjId" value="${param.prjId}"/>
				  		<div class="tab-pane <c:if test="${param.tab==null || param.tab=='prj'}">active</c:if>" id="prjPanel">
				  			<div class="enter-panel">
				  			<table class="table-dtl">
				  				<tr>
				  					<td class="title">编码 <span class="text-danger">*</span></td>
				  					<td><input type="text" class="form-control" id="code" placeholder="用户编码" value="${prjInfo.code}"></td>
				  				</tr>
				  				<tr>
				  					<td class="title">名称 <span class="text-danger">*</span></td>
				  					<td><input type="text" class="form-control" id="name" placeholder="名称" value="${prjInfo.name}"></td>
				  				</tr>
				  				<tr>
				  					<td class="title">根目录 <span class="text-danger">*</span></td>
				  					<td><input type="text" class="form-control" id="rootDir" placeholder="根目录" value="${prjInfo.rootDir}"/></td>
				  				</tr>
				  				<tr>
				  					<td class="title">备注</td>
				  					<td><input type="text" class="form-control" id="remark" placeholder="备注" value="${prjInfo.remark}"></td>
				  				</tr>
				  				<tr>
				  					<td class="title">状态 <span class="text-danger">*</span></td>
				  					<td><my:radio id="status" name="status" dictcode="prj_info_status" value="${prjInfo.status}" defvalue="10" exp="style=\"width: auto;\""/></td>
				  				</tr>
				  				<tr>
				  					<td class="title">容器类型 <span class="text-danger">*</span></td>
				  					<td><my:select id="container" headerKey="" headerValue="请选择容器类型" dictcode="prj_info_container" value="${prjInfo.container}" cssCls="form-control" /></td>
				  				</tr>
				  				<tr style="height: 110px;">
				  					<td class="title va-top">部署脚本 <span class="text-danger">*</span></td>
				  					<td><textarea class="form-control" rows="6" id="shellScript" placeholder="发布的shell脚本" style="height: 100px;">${prjInfo.shellScript}</textarea></td>
				  				</tr>
				  				<tr style="height: 90px;">
				  					<td class="title va-top">停止服务</td>
				  					<td><textarea class="form-control" rows="3" id="stopScript" placeholder="停止服务的shell脚本" style="height: 80px;">${prjInfo.stopScript}</textarea></td>
				  				</tr>
				  				<tr style="height: 90px;">
				  					<td class="title va-top">重启服务</td>
				  					<td><textarea class="form-control" rows="3" id="restartScript" placeholder="重启服务的shell脚本" style="height: 80px;">${prjInfo.restartScript}</textarea></td>
				  				</tr>
				  				<tr>
				  					<td class="title"></td>
				  					<td>
				  						<small>
											<a href="${webroot}/help.jsp#prjInfoParam" target="_blank">[prj.path]、[prj.name]、[current.date]、[current.time]等参数帮助</a>
											<span>|</span>
											<a href="${webroot}/help.jsp#prjInfoShell" target="_blank">Shell脚本内容解析</a>
										</small>
				  					</td>
				  				</tr>
				  				<my:auth mid="prjInfoManagerUpd">
				  				<tr>
				  					<td></td>
				  					<td><button type="button" id="saveBtn" class="btn btn-success enter-fn">保存</button>
				  						<span id="saveMsg" class="label label-danger"></span>
				  					</td>
				  				</tr>
				  				</my:auth>
				  			</table>
				  			</div>
				  		</div>
				    	<div class="tab-pane <c:if test="${param.tab=='config'}">active</c:if>" id="configPanel">
				    		<div class="enter-panel">
				  			<table class="table-dtl">
				  				<tr>
				  					<td class="title">类型 <span class="text-danger">*</span></td>
				  					<td>
				  						<label style="font-weight: normal;"><input type="radio" id="configType10" name="configType" class="" value="properties" style="width: auto;" checked="checked"> properties</label>&nbsp;&nbsp;
										<label style="font-weight: normal;"><input type="radio" id="configType20" name="configType" class="" value="yml" style="width: auto;"> yml</label>&nbsp;&nbsp;
				  					</td>
				  				</tr>
				  				<tr>
				  					<td class="title va-top">内容 <span class="text-danger">*</span></td>
				  					<td style="width: 100%;"><textarea rows="25" id="configContent" style="width: 100%;" class="form-control"></textarea></td>
				  				</tr>
				  				<my:auth mid="prjInfoManagerConfigUpd">
				  				<tr style="height: 60px;">
				  					<td></td>
				  					<td><button type="button" id="saveConfigBtn" onclick="configInfo.save(0,'saveConfigBtn')" class="btn btn-success enter-fn">保存</button>
				  						<button type="button" id="saveRefreshConfigBtn" onclick="configInfo.save(1,'saveRefreshConfigBtn')" class="btn btn-default enter-fn">保存并刷新配置</button>
				  						<span id="saveConfigMsg" class="label label-danger"></span>
				  					</td>
				  				</tr>
				  				</my:auth>
				  			</table>
				    			
				    		</div>
				    	</div>
				    	<div class="tab-pane <c:if test="${param.tab=='api'}">active</c:if>" id="apiPanel">
				    		<div class="table-tool-panel">
								<div class="row">
									<div class="col-sm-9 enter-panel">
										<input type="text" class="form-control input-sm w-120" id="apiName" placeholder="接口名称" value=""/>
										<input type="text" class="form-control input-sm w-120" id="apiPath" placeholder="接口地址" value=""/>
										<my:select id="apiIsUse" dictcode="boolean" headerKey="" headerValue="是否使用" value="1" cssCls="form-control input-sm w-80" change="apiInfo.loadInfo(1)"/>
							  			<button type="button" class="btn btn-sm btn-default enter-fn" onclick="apiInfo.loadInfo(1)">查询</button>
									</div>
									<div class="col-sm-3 text-right">
									</div>
								</div>
						  	</div>
							<div id="apiInfoPanel" class="table-panel"></div>
							<div id="apiInfoPage" class="table-page-panel"></div>
				    	</div>
				    	<div class="tab-pane <c:if test="${param.tab=='version'}">active</c:if>" id="versionPanel">
						  	<div class="layout">
						  		<div class="left" style="width: 40%;">
						  			<div class="table-tool-panel">
										<div class="row">
											<div class="col-sm-6 enter-panel">
											</div>
											<div class="col-sm-6 text-right">
											  	<div class="btn-group">
											  		<a href="javascript:;" class="btn btn-success btn-sm" onclick="versionInfo.edit()">新增版本</a>
											  	</div>
											</div>
										</div>
								  	</div>
									<div id="versionInfoPanel" class="table-panel"></div>
									<div id="versionInfoPage" class="table-page-panel"></div>
						  		</div>
						  		<div class="right" style="width: 60%;">
						  			<div class="table-tool-panel">
										<div class="row">
											<div class="col-sm-6 text-muted" id="clientInfoTitle"></div>
											<div class="col-sm-6 text-right">
											  	<div class="btn-group">
												<select id="refreshInterval" onchange="versionClientInfo.refreshChange()" class="form-control input-sm" style="width: 90px;">
													<option value="">刷新:关闭</option>
													<option value="5">5s刷新一次</option>
													<option value="10">10s刷新一次</option>
												</select>
										  	</div>
										  	<div class="btn-group">
										  		<my:auth mid="prjVersionDeployment"><a href="javascript:;" class="btn btn-info btn-sm" onclick="versionClientInfo.releaseAll()">全部署</a></my:auth>
										  		<a href="javascript:;" class="btn btn-success btn-sm" onclick="versionClientInfo.edit()">+ 客户端</a>
										  	</div>
											</div>
										</div>
								  	</div>
									<div id="versionClientInfoPanel" class="table-panel"></div>
									<div id="versionClientInfoPage" class="table-page-panel"></div>
						  		</div>
						  	</div>
				    	</div>
				    	<div class="tab-pane <c:if test="${param.tab=='monitor'}">active</c:if>" id="monitorPanel">
				    		<div class="table-tool-panel">
								<div class="row">
									<div class="col-sm-9 enter-panel">
										<div class="btn-group">
											<my:select id="monitorStatus" headerKey="" headerValue="全部状态" dictcode="prj_monitor_monitor_status" cssCls="form-control input-sm" />
										</div>
							  			<button type="button" class="btn btn-sm btn-default enter-fn" onclick="monitorInfo.loadInfo(1)">查询</button>
									</div>
									<div class="col-sm-3 text-right">
										<div class="btn-group">
											<select id="refreshIntervalMonitor" onchange="monitorInfo.refreshChange()" class="form-control input-sm">
												<option value="">自动刷新:关闭</option>
												<option value="5">5s刷新一次</option>
												<option value="10">10s刷新一次</option>
											</select>
									  	</div>
									</div>
								</div>
						  	</div>
							<div id="monitorInfoPanel" class="table-panel"></div>
							<div id="monitorInfoPage" class="table-page-panel"></div>
				    	</div>
				  		<div class="tab-pane <c:if test="${param.tab=='cache'}">active</c:if>" id="cachePanel">
				    		<div class="table-tool-panel">
								<div class="row">
									<div class="col-sm-10 enter-panel">
										<input type="text" style="width: 250px;display: inline;" class="form-control input-sm" id="cacheKey" placeholder="key(abc*代表获取abc开头的key列表)" value="">
										<input type="text" style="width: 80px;display: inline;" class="form-control input-sm" id="cacheNum" placeholder="默认100条" value="">
								  		<button type="button" class="btn btn-sm btn-default enter-fn" onclick="cacheInfo.loadInfo(1)">查询</button>
								  		<button type="button" class="btn btn-sm btn-danger" onclick="cacheInfo.delBatch()">批量删除</button>
								  		<a href="javascript:;" class="btn btn-link btn-sm" onclick="cacheInfo.lookApi()"><span class="text-success">跨系统调度链接</span></a>
									</div>
									<div class="col-sm-2 text-right">
									</div>
								</div>
						  	</div>
							<div id="cacheInfoPanel" class="table-panel"><p class="text-muted" style="padding: 10px;">请输入key搜索</p></div>
							<div id="cacheInfoPage" class="table-page-panel"></div>
				    	</div>
				  		<div class="tab-pane <c:if test="${param.tab=='code'}">active</c:if>" id="codePanel">
						  	<div class="layout">
						  		<div class="left" style="width: 40%;">
						  			<div class="table-tool-panel">
										<div class="row">
											<div class="col-sm-6 enter-panel">
											</div>
											<div class="col-sm-6 text-right">
											  	<div class="btn-group">
											  		<a href="javascript:;" class="btn btn-default btn-sm" onclick="codeInfo.impTemplate()">导入默认模板</a>
											  	</div>
											  	<div class="btn-group">
											  		<a href="javascript:;" class="btn btn-success btn-sm" onclick="codeInfo.edit()">新增模板</a>
											  	</div>
											</div>
										</div>
								  	</div>
									<div id="codeInfoPanel" class="table-panel"></div>
									<div id="codeInfoPage" class="table-page-panel"></div>
						  		</div>
						  		<div class="right" style="width: 60%;">
						  			<div class="table-tool-panel">
										<div class="row">
											<div class="col-sm-4 text-muted" id="createTitle">
											</div>
											<div class="col-sm-8 text-right">
											  	<div class="btn-group">
											  		<a href="javascript:;" class="btn btn-success btn-sm" onclick="codeCreateInfo.edit()">生成源码</a>
											  	</div>
											</div>
										</div>
								  	</div>
									<div id="codeCreateInfoPanel" class="table-panel"></div>
									<div id="codeCreateInfoPage" class="table-page-panel"></div>
						  		</div>
						  	</div>
				    	</div>
				  		<div class="tab-pane <c:if test="${param.tab=='ds'}">active</c:if>" id="dsPanel">
				    		<div class="table-tool-panel">
								<div class="row">
									<div class="col-sm-9 enter-panel">
										<input type="text" class="form-control input-sm w-120" id="apiName" placeholder="接口名称" value=""/>
										<input type="text" class="form-control input-sm w-120" id="apiPath" placeholder="接口地址" value=""/>
										<my:select id="apiIsUse" dictcode="boolean" headerKey="" headerValue="是否使用" value="1" cssCls="form-control input-sm w-80" change="apiInfo.loadInfo(1)"/>
							  			<button type="button" class="btn btn-sm btn-default enter-fn" onclick="apiInfo.loadInfo(1)">查询</button>
									</div>
									<div class="col-sm-3 text-right">
										<div class="btn-group">
									  		<a href="javascript:;" class="btn btn-success btn-sm" onclick="dsInfo.edit()">新增数据源</a>
									  	</div>
									</div>
								</div>
						  	</div>
							<div id="dsInfoPanel" class="table-panel"></div>
							<div id="dsInfoPage" class="table-page-panel"></div>
				    	</div>
				  	</div>
				  	
				</div>
			</div>
		</div>
		<br clear="all">
	</div>
	<jsp:include page="/WEB-INF/view/inc/js.jsp"></jsp:include>
	<jsp:include page="/WEB-INF/view/inc/utils/page.jsp"></jsp:include>
<script type="text/javascript">
var dsInfoPage = undefined;
var dsInfo = {
		init: function() {
			dsInfo.loadInfo(1);
		},
		loadInfo : function(page) {
			if(!dsInfoPage) {
				dsInfoPage = new Page('dsInfoPage', dsInfo.loadInfo, 'dsInfoPanel', 'dsInfoPage');
				dsInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
				                         '<th width="120">编码</th>',
				                         '<th width="80">类型</th>',
				                         '<th>jdbc的URL</th>',
				                         '<th width="120">用户名</th>',
				                         '<th width="150">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				dsInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined)
				dsInfoPage.page = page;

			JUtil.ajax({
				url : '${webroot}/prjDs/f-json/pageQuery',
				data : { prjId: '${param.prjId}', page:dsInfoPage.page, size:dsInfoPage.size },
				beforeSend: function(){ dsInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ dsInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							var _statusName = '';
							return ['<tr>',
							    	'<td>',obj.code,'</td>',
							    	'<td>',obj.type,'</td>',
							    	'<td>',obj.url,'</td>',
							    	'<td>',obj.username,'</td>',
							    	'<td><a class="glyphicon glyphicon-edit text-success" href="javascript:dsInfo.edit(\'',obj.code,'\')" title="修改"></a>',
							    	'&nbsp; <a class="glyphicon glyphicon-remove text-success" href="javascript:dsInfo.del(\'',obj.code,'\')" title="删除"></a>',
							    	'&nbsp; &nbsp;<a class="glyphicon text-success" href="javascript:dsInfo.test(\'',obj.code,'\')" title="测试链接信息是否成功">测试连接</a>',
							    	'</td>',
								'</tr>'].join('');
						}
						dsInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		edit : function(code) {
			dialog({
				title: '编辑数据源',
				url: webroot + '/prjDs/f-view/edit.shtml?prjId=${param.prjId}&code='+(code?code:''),
				type: 'iframe',
				width: 520,
				height: 450
			});
		},
		test : function(code) {
			JUtil.ajax({
				url : '${webroot}/prjDs/f-json/test.shtml',
				data : {
					prjId: '${param.prjId}',
					code: code,
				},
				success : function(json) {
					if (json.code === 0) {
						message('执行测试语句成功');
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					else
						message(json.message);
				}
			});
		},
		del : function(code) {
			if(confirm('您确定要删除该数据源吗?')) {
				JUtil.ajax({
					url : '${webroot}/prjDs/f-json/delete.shtml',
					data : { prjId: '${param.prjId}', code: code },
					success : function(json) {
						if (json.code === 0) {
							message('删除成功');
							dsInfo.loadInfo(1);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		}
};

var codeInfoPage = undefined;
var codeInfo = {
		init: function() {
			codeInfo.loadInfo(1);
			codeCreateInfo.loadInfo(1);
		},
		loadInfo : function(page) {
			if(!codeInfoPage) {
				codeInfoPage = new Page('codeInfoPage', codeInfo.loadInfo, 'codeInfoPanel', 'codeInfoPage');
				codeInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
				                         '<th width="80">类型</th>',
				                         '<th>名称</th>',
				                         '<th width="60">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				codeInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined)
				codeInfoPage.page = page;

			JUtil.ajax({
				url : '${webroot}/codeTemplate/f-json/pageQuery',
				data : { prjId: '${param.prjId}', code: '${param.prjId}', page:codeInfoPage.page, size:codeInfoPage.size },
				beforeSend: function(){ codeInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ codeInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							var _statusName = '';
							return ['<tr>',
							    	'<td>',obj.typeName,'</td>',
							    	'<td>',obj.name,'</td>',
							    	'<td><a class="glyphicon glyphicon-edit text-success" href="javascript:codeInfo.edit(\'',obj.code,'\',\'',obj.name,'\')" title="修改"></a>',
							    	'&nbsp; <a class="glyphicon glyphicon-remove text-success" href="javascript:codeInfo.del(\'',obj.code,'\',\'',obj.name,'\')" title="删除"></a>',
							    	'</td>',
								'</tr>'].join('');
						}
						codeInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		edit : function(code, name) {
			dialog({
				title: '编辑模板',
				url: webroot + '/codeTemplate/f-view/edit?prjId=${param.prjId}&code='+(code?code:'') + '&name='+(name?name:''),
				type: 'iframe',
				width: 620,
				height: 510
			});
		},
		impTemplate: function() {
			if(confirm('您确定要导入默认模板吗?')) {
				JUtil.ajax({
					url : '${webroot}/codeTemplate/f-json/impDefault',
					data : { code: '${param.prjId}', prjId: '${param.prjId}' },
					success : function(json) {
						if (json.code === 0) {
							message('导入默认模板成功');
							codeInfo.loadInfo(1);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		del : function(code, name) {
			if(confirm('您确定要删除该模板吗?')) {
				JUtil.ajax({
					url : '${webroot}/codeTemplate/f-json/delete',
					data : { code: code, name: name },
					success : function(json) {
						if (json.code === 0) {
							message('删除成功');
							codeInfo.loadInfo(1);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		}
};

var codeCreateInfoPage = undefined;
var codeCreateInfo = {
		loadInfo : function(page) {
			//$('#createTitle').html('<small>发布的版本号：</small><span class="label label-warning">' + client.version + '</span>');
			if(!codeCreateInfoPage) {
				codeCreateInfoPage = new Page('codeCreateInfoPage', codeCreateInfo.loadInfo, 'codeCreateInfoPanel', 'codeCreateInfoPage');
				codeCreateInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
				                         '<th width="80">编号</th>',
				                         '<th width="120">包路径</th>',
				                         '<th>表名</th>',
				                         '<th width="110">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				codeCreateInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined)
				codeCreateInfoPage.page = page;

			JUtil.ajax({
				url : '${webroot}/codeCreate/f-json/pageQuery',
				data : { code: '${param.prjId}', page:codeCreateInfoPage.page, size:codeCreateInfoPage.size },
				beforeSend: function(){ codeCreateInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ codeCreateInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							var _finish = '';
							if(obj.finishTime) {
								_finish = '&nbsp; <a class="glyphicon text-success" href="javascript:codeCreateInfo.download('+obj.id+')" title="点击下载源码">下载源码</a>';
							}
							
							return ['<tr>',
							    	'<td>',obj.id,'<br/>',
							    	'<td>',obj.packagePath,'</td>',
							    	'<td style="word-break:break-all">',obj.tables,'</td>',
							    	'<td><a class="glyphicon glyphicon-edit text-success" href="javascript:codeCreateInfo.edit(',obj.id,')" title="修改"></a>',
							    	'&nbsp; <a class="glyphicon glyphicon-remove text-success" href="javascript:codeCreateInfo.del(',obj.id,')" title="删除"></a>',
							    	_finish,
							    	'</td>',
								'</tr>'].join('');
						}
						codeCreateInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		//编辑
		edit : function(id) {
			dialog({
				title: '编辑生成源码',
				url: webroot + '/codeCreate/f-view/edit?prjId=${param.prjId}&code=${param.prjId}&id='+(id?id:''),
				type: 'iframe',
				width: 520,
				height: 380
			});
		},
		del : function(id) {
			if(confirm('您确定要删除该源码吗?')) {
				JUtil.ajax({
					url : '${webroot}/codeCreate/f-json/delete',
					data : { id: id },
					success : function(json) {
						if (json.code === 0) {
							message('删除成功');
							codeCreateInfo.loadInfo(1);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		download: function(id) {
			window.open(webroot + '/codeCreate/f-view/download?id=' + id);
		}
};

var cacheInfo = {
		init: function() {
		},
		loadInfo : function() {
			var panel = $('#cacheInfoPanel').empty();
			var prjId = $('#prjId').val();
			var key = $('#cacheKey').val();
			if(JUtil.isEmpty(key)) {
				alert('请输入key');
				return;
			}
			var num = $('#cacheNum').val();
			if (num == '') {
				num = '100';
			}
			JUtil.ajax({
				url : '${webroot}/cacheInfo/f-json/findKey',
				data : { prjId: prjId, key: key, num: num },
				error : function(json){ alert('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						var cont = ['<table class="table table-striped table-hover"><thead><tr class="info">',
                         '<th>key</th>',
                         '<th width="100">操作</th>',
                         '</tr></thead><tbody>'];
						if(json.body.length > 0) {
							$.each(json.body, function(i, obj) {
								cont.push('<tr>',
								    	'<td>',obj,'</td>',
								    	'<td><a class="glyphicon glyphicon-remove text-success" href="javascript:cacheInfo.del(\'',obj,'\')" title="删除该key"></a>',
								    	'&nbsp; &nbsp;<a class="glyphicon text-success" href="javascript:cacheInfo.look(\'',obj,'\')" title="查看值">查看值</a>',
								    	'</td>',
									'</tr>');
							});
						} else {
							cont.push('<tr><td colspan="5" align="center">没有记录</td>',
							    	'</td></tr>');
						}
						cont.push('</tbody></table>');
						panel.append(cont.join(''));
						$('#cacheInfoPage').html('<small class="text-muted">共' + json.body.length + '条记录</small>');
					} else if(json.code == '10002') panel.append('<label class="label label-danger">暂时没有开通redis的管理功能</label>');
					else panel.append('<label class="label label-danger">' + JUtil.msg.ajaxErr + '</label>');
				}
			});
		},
		//查看远程调度链接
		lookApi: function() {
			var prjId = $('#prjId').val();
			var key = $('#cacheKey').val();
			if(JUtil.isEmpty(key)) {
				alert('请输入key');
				return;
			}
			JUtil.ajax({
				url : '${webroot}/cacheInfo/f-json/getLink',
				data : { prjId: prjId, key: key },
				success : function(json) {
					if (json.code === 0) {
						var url = json.body;
						dialog({
							content: ['<div>批量删除：<small id="batchDeletePanel" class="text-success" onclick="JUtil.selectText(\'batchDeletePanel\')">',url.replace('{methodName}', 'deleteBatch'),'</small></div>'].join(''),
							width: 500,
							height: 300
						});
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					else
						message(json.message);
				}
			});
		},
		//查看value
		look : function(key) {
			var prjId = $('#prjId').val();
			JUtil.ajax({
				url : '${webroot}/cacheInfo/f-json/get',
				data : { prjId: prjId, key: key },
				success : function(json) {
					if (json.code === 0) {
						alert(['<div><textarea rows="15" class="form-control">',json.body.toString(),'</textarea></div>'].join(''));
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					 else if(json.code == '10002')
						message('暂时没有开通redis的查看值功能');
					else
						message(json.message);
				}
			});
		},
		//批量删除
		delBatch : function() {
			if(confirm('您确定要批量删除该Key吗?')) {
				var prjId = $('#prjId').val();
				JUtil.ajax({
					url : '${webroot}/cacheInfo/f-json/deleteBatch',
					data : { prjId: prjId, key: $('#cacheKey').val() },
					success : function(json) {
						if (json.code === 0) {
							message('批量删除成功');
							cacheInfo.loadInfo();
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		//删除
		del : function(key) {
			if(confirm('您确定要删除该Key吗?')) {
				var prjId = $('#prjId').val();
				JUtil.ajax({
					url : '${webroot}/cacheInfo/f-json/delete',
					data : { prjId: prjId, key: key },
					success : function(json) {
						if (json.code === 0) {
							message('删除成功');
							cacheInfo.loadInfo();
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		}
};

var monitorInfoPage = undefined;
var monitorInfo = {
		init: function() {
			monitorInfo.loadInfo(1);
		},
		loadInfo : function(page) {
			if(!monitorInfoPage) {
				monitorInfoPage = new Page('monitorInfoPage', monitorInfo.loadInfo, 'monitorInfoPanel', 'monitorInfoPage');
				monitorInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
                    '<th>项目名称</th>',
                    '<th>服务信息</th>',
                    '<th>类型</th>',
                    '<th>开启监控</th>',
                    '<th>监控状态 / 监控时间</th>',
                    '<th width="120">操作</th>',
                    '</tr></thead><tbody>'].join('');
				monitorInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined) {
				monitorInfoPage.page = page;
			}

			JUtil.ajax({
				url : '${webroot}/prjMonitor/f-json/pageQuery',
				data : { page:monitorInfoPage.page, size:monitorInfoPage.size,
					prjId:$('#prjId').val(), monitorStatus:$('#monitorStatus').val()
				},
				beforeSend: function(){ monitorInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ monitorInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							var _msCont = [];
							var _monitorIsCls = '';
							var _monitorTime = '';
							var _stopSrv = [];
							if(obj.monitorIs === 0) {
								_monitorIsCls = ' class="text-danger"';
							} else {
								_monitorIsCls = ' class="text-success"';
								if(obj.monitorStatus === <%=PrjMonitorMonitorStatus.ERROR.getCode()%>) {
									_msCont.push('<span class="text-danger">',obj.monitorStatusName,'&nbsp; &nbsp;</span>');
									_msCont.push('<small class="text-muted">检测失败次数：',obj.monitorFailNum);
									_msCont.push('</small>');
								} else {
									_msCont.push('<span class="text-success">',obj.monitorStatusName,'&nbsp; &nbsp;</span>');
									
									_stopSrv.push('&nbsp; |&nbsp; <a class="glyphicon text-success" href="javascript:monitorInfo.stopSrv(',obj.prjmId,')" title="停止服务">停止服务</a>');
								}
								_monitorTime = '<br><small class="text-muted">监控时间: ' + obj.monitorTime + '</small>';
							}
							return ['<tr>',
							    	'<td>',obj.prjName,'</td>',
							    	'<td>',obj.remark,'</td>',
							    	'<td>',obj.typeName,'</td>',
							    	'<td><span',_monitorIsCls,'>',obj.monitorIsName,'</span></td>',
							    	'<td>',_msCont.join(''),_monitorTime,'</td>',
							    	'<td><a class="glyphicon glyphicon-remove text-success" href="javascript:monitorInfo.del(',obj.prjmId,')" title="删除"></a>',
							    	_stopSrv.join(''),
							    	'</td>',
								'</tr>'].join('');
						}
						monitorInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		del : function(id) {
			if(confirm('您确定要删除该项目监控吗?')) {
				JUtil.ajax({
					url : '${webroot}/prjMonitor/f-json/delete',
					data : { prjmId: id },
					success : function(json) {
						if (json.code === 0) {
							message('删除成功');
							monitorInfo.loadInfo(1);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		stopSrv : function(prjmId) {
			if(confirm('您确定要停止该服务吗?')) {
				JUtil.ajax({
					url : '${webroot}/prjMonitor/f-json/stopSrv',
					data : { prjmId: prjmId },
					success : function(json) {
						if (json.code === 0) {
							message('服务停止成功，过程会有一定的延时');
							monitorInfo.loadInfo(1);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		refreshChange: function() {
			if(monitorInfo.interval) {
				window.clearInterval(monitorInfo.interval);
			}
			var _refresh = $('#refreshIntervalMonitor').val();
			if(JUtil.isEmpty(_refresh)) {
				return;
			}
			monitorInfo.interval = window.setInterval('monitorInfo.loadInfo()', _refresh * 1000);
		}
};

var versionInfoPage = undefined;
var versionInfo = {
		init: function() {
			versionInfo.loadInfo(1);
		},
		loadInfo: function(page) {
			if(!versionInfoPage) {
				versionInfoPage = new Page('versionInfoPage', versionInfo.loadInfo, 'versionInfoPanel', 'versionInfoPage');
				versionInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
				                         '<th>版本号</th>',
				                         '<th>参考版本</th>',
				                         '<th width="80">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				versionInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined)
				versionInfoPage.page = page;

			JUtil.ajax({
				url : '${webroot}/prjVersion/f-json/pageQuery',
				data : { prjId: $('#prjId').val(), page:versionInfoPage.page, size:versionInfoPage.size },
				beforeSend: function(){ versionInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ versionInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							var _isReleaseName = '';
							var trClass = '';
							if(obj.isRelease === 1) {
								_isReleaseName = '<small class="text-success">('+(obj.isFirstDeploy==1?'首次':'')+'发布)</small>';
								if(versionClientInfo.version === undefined) {
									//为第一次进来，默认加载发布的项
									versionClientInfo.version = obj.version;
									versionClientInfo.loadInfo(1);
									trClass = 'success';
								}
							} else {
								_isReleaseName = '<small class="text-danger">(历史)</small>';
							}
							var _rbVersion = obj.rbVersion;
							if(JUtil.isNotEmpty(_rbVersion) && _rbVersion.length > 10) {
								_rbVersion = _rbVersion.substring(0, 10) + '...';
							}
							return ['<tr class="',trClass,'" onclick="versionInfo.cli(this,${param.prjId}, \'',obj.version,'\')">',
							    	'<td><span id="version_',obj.version,'" onclick="JUtil.selectText(\'version_',obj.version,'\')">',obj.version,'</span> ',_isReleaseName,'</td>',
							    	'<td title="',obj.rbVersion,'">',_rbVersion,'</td>',
							    	'<td><a class="glyphicon glyphicon-edit text-success" href="javascript:versionInfo.edit(\'',obj.version,'\')" title="修改"></a>',
							    	'&nbsp;&nbsp; <span class="dropdown opt-more">',
									'<a class="glyphicon text-success dropdown-toggle" href="javascript:;" data-toggle="dropdown">更多...</a>',
									'<ul class="dropdown-menu" role="menu">',
									'<li role="presentation"><a href="javascript:versionInfo.del(\'',obj.version,'\')" title="删除">删除</a></li>',
									//'<li role="presentation"><a href="javascript:versionInfo.script(\'',obj.version,'\')" title="设置升级的脚本">升级脚本</a></li>',
									'<li role="presentation"><a href="',webroot,'/sysFile/f-view/download.shtml?url=',obj.pathUrl,'" target="_blank" title="下载发布的包">下载发布包</a></li>',
									'</ul>',
									'</span>',
									'</td>',
								'</tr>'].join('');
						}
						versionInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
						JUtil.sys.initOptMore();
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		edit : function(id) {
			dialog({
				title: '编辑项目版本',
				url: webroot + '/prjVersion/f-view/edit?prjId=${param.prjId}&version='+(id?id:''),
				type: 'iframe',
				width: 590,
				height: 500
			});
		},
		script: function(version) {
			location = webroot + '/prjVersionScript/f-view/manager?prjId=${param.prjId}&version='+(version?version:'');
		},
		del : function(version) {
			if(confirm('您确定要删除该版本吗?')) {
				JUtil.ajax({
					url : '${webroot}/prjVersion/f-json/delete',
					data : { prjId: '${param.prjId}', version: version },
					success : function(json) {
						if (json.code === 0) {
							message('删除成功');
							versionInfo.loadInfo();
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		//发布到客户端的管理
		cli : function(_this, prjId, version) {
			var tr = $(_this);
			tr.parent().find('tr').each(function(i, obj) {
				$(obj).removeClass('success');
			});
			tr.addClass('success');
			versionClientInfo.version = version;
			versionClientInfo.loadInfo(1);
			//location = '${webroot}/prjClient/f-view/manager.shtml?prjId=' + prjId + '&version=' + version;
		}
};

var versionClientInfoPage = undefined;
var versionClientInfo = {
		loadInfo : function(page) {
			if(versionClientInfo.version != undefined) {
				$('#clientInfo').css('display', 'block');
				$('#clientInfoMsg').css('display', 'none');
			}
			$('#clientInfoTitle').html('<small>部署版本：</small><span class="label label-warning">' + versionClientInfo.version + '</span>');
			if(!versionClientInfoPage) {
				versionClientInfoPage = new Page('versionClientInfoPage', versionClientInfo.loadInfo, 'versionClientInfoPanel', 'versionClientInfoPage');
				versionClientInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
				                         '<th>客户端</th>',
				                         '<th>状态</th>',
				                         '<th>发布时间</th>',
				                         '<th width="110">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				versionClientInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined)
				versionClientInfoPage.page = page;

			JUtil.ajax({
				url : '${webroot}/prjClient/f-json/pageQuery',
				data : { prjId: $('#prjId').val(), version: versionClientInfo.version, page:versionClientInfoPage.page, size:versionClientInfoPage.size },
				beforeSend: function(){ versionClientInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ versionClientInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							var _statusName = '';
							if(obj.status === <%=PrjClientStatus.WAIT.getCode()%>) {
								_statusName = '<span class="text-muted">'+obj.statusName+'</span>';
							} else if(obj.status === <%=PrjClientStatus.ING.getCode()%>) {
								_statusName = '<span class="text-warning">'+obj.statusName+'</span>';
							} else if(obj.status === <%=PrjClientStatus.SUCC.getCode()%>) {
								_statusName = '<span class="text-success">'+obj.statusName+'</span>';
							} else if(obj.status === <%=PrjClientStatus.FAIL.getCode()%>) {
								_statusName = '<span class="text-danger">'+obj.statusName+'</span>';
							} else {
								_statusName = '<span class="text-muted">'+obj.statusName+'</span>';
							}
							return ['<tr>',
							    	'<td>',obj.clientName,'<br/>',
							    	'<span class="text-success">',obj.ip,':',obj.port,'</span></td>',
							    	'<td>',_statusName,(JUtil.isNotEmpty(obj.statusMsg) ? ' | <a href="javascript:versionClientInfo.lookResult(\''+obj.clientId+'\');">结果</a>':''),'<textarea class="hidden" id="statusMsg',obj.clientId,'">',obj.statusMsg,'</textarea></td>',
							    	'<td>',obj.releaseTime,'</td>',
							    	'<td><my:auth mid="prjVersionDeployment"><a class="glyphicon text-success" href="javascript:versionClientInfo.release(\'',obj.clientId,'\')" title="发布到客户端(相当于重新发布项目)">部署</a>',
							    	'&nbsp; &nbsp;&nbsp;</my:auth><span class="dropdown opt-more">',
									'<a class="glyphicon text-success dropdown-toggle" href="javascript:;" data-toggle="dropdown">更多...</a>',
									'<ul class="dropdown-menu" role="menu">',
									'<li role="presentation"><a href="javascript:versionClientInfo.edit(\'',obj.clientId,'\')" title="修改">修改</a></li>',
									'<li role="presentation"><a href="javascript:versionClientInfo.del(\'',obj.clientId,'\')" title="删除">删除</a></li>',
									'<li role="presentation"><a href="javascript:versionClientInfo.shell(\'',obj.clientId,'\')" title="设置发布的Shell">设命令</a></li>',
									'<li role="presentation"><a href="javascript:versionClientInfo.lookLog(\'',obj.clientId,'\')" title="查询项目的日志文件">看日志</a></li>',
									'<my:auth mid="prjVersionStop"><li role="presentation"><a href="javascript:versionClientInfo.stopService(\'',obj.clientId,'\')" title="停止服务">停止服务</a></li></my:auth>',
									'<my:auth mid="prjVersionRestart"><li role="presentation"><a href="javascript:versionClientInfo.restartService(\'',obj.clientId,'\')" title="重启服务">重启服务</a></li></my:auth>',
									'</ul>',
									'</span>',
							    	'</td>',
								'</tr>'].join('');
						}
						versionClientInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
						JUtil.sys.initOptMore();
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		//查看结果
		lookResult : function(clientId) {
			var _msg = $('#statusMsg' + clientId).val();
			if(JUtil.isEmpty(_msg)) {
				_msg = '暂无';
			}
			alert(_msg);
		},
		//编辑客户端
		edit : function(clientId) {
			dialog({
				title: '编辑发布到的客户端',
				url: webroot + '/prjClient/f-view/edit.shtml?prjId=${param.prjId}&version='+versionClientInfo.version+'&clientId='+(clientId?clientId:''),
				type: 'iframe',
				width: 420,
				height: 290
			});
		},
		//查看日志
		lookLog : function(clientId) {
			var url = webroot + '/prjClient/f-view/lookLog.shtml?prjId=${param.prjId}&version='+versionClientInfo.version+'&clientId='+(clientId?clientId:'');
			
			open(url);
			/* dialog({
				title: '查看日志',
				url: webroot + '/prjClient/f-view/lookLog.shtml?prjId=${param.prjId}&version=${param.version}&clientId='+(clientId?clientId:''),
				type: 'iframe',
				width: 700,
				height: 500
			}); */
		},
		//设置发布的shell
		shell : function(clientId) {
			dialog({
				title: '设置'+clientId+'发布的shell',
				url: webroot + '/prjClient/f-view/shell?prjId=${param.prjId}&version='+versionClientInfo.version+'&clientId='+(clientId?clientId:''),
				type: 'iframe',
				width: 620,
				height: 500
			});
		},
		del : function(id) {
			if(confirm('您确定要删除该客户端吗?')) {
				JUtil.ajax({
					url : '${webroot}/prjClient/f-json/delete',
					data : { prjId: '${param.prjId}', version: versionClientInfo.version, clientId: id },
					success : function(json) {
						if (json.code === 0) {
							message('删除成功');
							versionClientInfo.loadInfo(1);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		//停止服务
		stopService: function(clientId) {
			if(confirm('您确定要停止'+clientId+'客户端的服务吗?')) {
				JUtil.ajax({
					url : '${webroot}/prjClient/f-json/stopService',
					data : { prjId: '${param.prjId}', version: versionClientInfo.version, clientId: clientId },
					success : function(json) {
						if (json.code === 0) {
							message('操作成功');
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		//重启服务
		restartService: function(clientId) {
			if(confirm('您确定要重启'+clientId+'客户端的服务吗?')) {
				JUtil.ajax({
					url : '${webroot}/prjClient/f-json/restartService',
					data : { prjId: '${param.prjId}', version: versionClientInfo.version, clientId: clientId },
					success : function(json) {
						if (json.code === 0) {
							message('操作成功');
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		//发布到所有客户端
		releaseAll : function() {
			if(confirm('您确定要发布到所有客户端吗?')) {
				JUtil.ajax({
					url : '${webroot}/prjClient/f-json/releaseAll',
					data : { prjId: '${param.prjId}', version: versionClientInfo.version },
					success : function(json) {
						if (json.code === 0) {
							message('操作成功');
							setTimeout('versionClientInfo.loadInfo()', 3000);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		//发布到指定客户端
		release : function(clientId) {
			if(confirm('您确定要发布到指定的客户端吗?')) {
				JUtil.ajax({
					url : '${webroot}/prjClient/f-json/release',
					data : { prjId: '${param.prjId}', version: versionClientInfo.version, clientId: clientId },
					success : function(json) {
						if (json.code === 0) {
							message('操作成功');
							setTimeout('versionClientInfo.loadInfo()', 3000);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		},
		refreshChange: function() {
			if(versionClientInfo.interval) {
				window.clearInterval(versionClientInfo.interval);
			}
			var _refresh = $('#refreshInterval').val();
			if(JUtil.isEmpty(_refresh)) {
				return;
			}
			versionClientInfo.interval = window.setInterval('versionClientInfo.loadInfo()', _refresh * 1000);
		}
};

var apiInfoPage = undefined;
var apiInfo = {
		init: function() {
			apiInfo.loadInfo(1);
		},
		loadInfo : function(page) {
			if(!apiInfoPage) {
				apiInfoPage = new Page('apiInfoPage', apiInfo.loadInfo, 'apiInfoPanel', 'apiInfoPage');
				apiInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
				                         '<th>名称</th>',
				                         '<th>地址</th>',
				                         '<th>使用</th>',
				                         '<th width="80">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				apiInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined) {
				apiInfoPage.page = page;
			}

			JUtil.ajax({
				url : '${webroot}/prjApi/f-json/pageQuery',
				data : { page:apiInfoPage.page, size:apiInfoPage.size, prjId: $('#prjId').val(),
					name: $('#apiName').val(), path: $('#apiPath').val(), isUse: $('#apiIsUse').val() },
				beforeSend: function(){ apiInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ apiInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							var _isUseCls = '';
							if(obj.isUse === 0) {
								_isUseCls = ' class="text-danger"';
							} else {
								_isUseCls = ' class="text-success"';
							}
							return ['<tr>',
							    	'<td>',obj.name,'</td>',
							    	'<td>',obj.path,'</td>',
							    	'<td><span',_isUseCls,'>',obj.isUseName,'</span></td>',
							    	'<td><a class="text-success" href="javascript:apiInfo.dtl(\'',obj.path,'\')" title="查看接口详情">详情</a>',
							    	'</td>',
								'</tr>'].join('');
						}
						apiInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		dtl : function(path) {
			var url = '${webroot}/prjApi/f-view/dtl.shtml?prjId=' + $('#prjId').val() + '&path=' + encodeURI(path);
			window.open(url);
		}
};

var configInfo = {
		init: function() {
			JUtil.ajax({
				url: '${webroot}/msConfig/f-json/getUseByPrjId',
				data: {
					prjId: $('#prjId').val()
				},
				success : function(json) {
					if (json.code === 0) {
						if (json.body) {
							$('#configContent').val(json.body.content);
							if (json.body.name.indexOf('.yml')!=-1) {
								$('#configType20').prop('checked', true);
							} else {
								$('#configType10').prop('checked', true);
							}
						}
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					else
						message(json.message);
				}
			});
		},
		save: function(isRefresh, btnId) {
			var saveMsg = $('#saveConfigMsg').empty();
			var type = $('input[name="configType"]:checked').val();
			var content = $('#configContent');
			if(JUtil.isEmpty(content.val())) {
				saveMsg.append('请输入内容');
				content.focus();
				return;
			}
			JUtil.ajax({
				eventId: btnId,
				url: '${webroot}/msConfig/f-json/save',
				data: {
					prjId: $('#prjId').val(),
					type: type,
					content: content.val(),
					isRefresh: isRefresh
				},
				success : function(json) {
					if (json.code === 0) {
						saveMsg.attr('class', 'label label-success').append('保存成功');
					}
					else if (json.code === -1)
						saveMsg.append(JUtil.msg.ajaxErr);
					else
						saveMsg.append(json.message);
				}
			});
		}
};

$(function() {
	var tab = '${param.tab}';
	if (tab != '') {
		${param.tab}Info.init();
	}
	$('#saveBtn').click(function() {
		var _saveMsg = $('#saveMsg').empty();
		
		var _prjId = $('#prjId').val();
		var _code = $('#code');
		if(JUtil.isEmpty(_code.val())) {
			_saveMsg.append('请输入编码');
			_code.focus();
			return;
		}
		var _name = $('#name');
		if(JUtil.isEmpty(_name.val())) {
			_saveMsg.append('请输入名称');
			_name.focus();
			return;
		}
		var _container = $('#container');
		if(JUtil.isEmpty(_container.val())) {
			_saveMsg.append('请选择容器类型');
			_container.focus();
			return;
		}
		var _shellScript = $('#shellScript');
		if(JUtil.isEmpty(_shellScript.val())) {
			_saveMsg.append('请输入发布的shell脚本');
			_shellScript.focus();
			return;
		}
		
		var _saveBtn = $('#saveBtn');
		var _orgVal = _saveBtn.html();
		_saveBtn.attr('disabled', 'disabled').html('保存中...');
		JUtil.ajax({
			url : '${webroot}/prjInfo/f-json/save.shtml',
			data : {
				prjId: _prjId,
				code: _code.val(),
				name: _name.val(),
				remark: $('#remark').val(),
				status: $('input[name="status"]:checked').val(),
				container: _container.val(),
				shellScript: _shellScript.val(),
				stopScript: $('#stopScript').val(),
				restartScript: $('#restartScript').val(),
				//tag: $('#tag').val(),
				rootDir: $('#rootDir').val()
			},
			success : function(json) {
				if (json.code === 0) {
					_saveMsg.attr('class', 'label label-success').append('保存成功');
				}
				else if (json.code === -1)
					_saveMsg.append(JUtil.msg.ajaxErr);
				else
					_saveMsg.append(json.message);
				_saveBtn.removeAttr('disabled').html(_orgVal);
			}
		});
	});
	
	var rootDir = $('#rootDir');
	if (rootDir.val() == '') {
		rootDir.val('/app/appsoft/');
	}
	$('#container').change(function() {
		var code = $('#code').val();
		var _shellScript = $('#shellScript');
		var stopScript = $('#stopScript');
		var restartScript = $('#restartScript');
		if($(this).val() == '<%=PrjInfoContainer.LINUX_TOMCAT.getCode()%>') {
			//类型为tomcat
			_shellScript.val(['cd /opt/apache-tomcat-7.0.32\n',
					'./bin/shutdown.sh\n',
					'cp [prj.path][prj.name] /opt/apache-tomcat-7.0.32/webapps\n',
					'rm -rf /opt/apache-tomcat-7.0.32/webapps/test.zip /opt/apache-tomcat-7.0.32/webapps/test\n',
					'mv /opt/apache-tomcat-7.0.32/webapps/[prj.name] /opt/apache-tomcat-7.0.32/webapps/test.zip\n',
					'cd /opt/apache-tomcat-7.0.32/webapps\n',
					'unzip test.zip\n',
					'cd /opt/apache-tomcat-7.0.32\n',
					'./bin/startup.sh'].join(''));
			stopScript.val(['cd /opt/apache-tomcat-7.0.32\n',
				'./bin/shutdown.sh'].join(''));
			restartScript.val(['cd /opt/apache-tomcat-7.0.32\n',
				'./bin/shutdown.sh\n',
				'cd /opt/apache-tomcat-7.0.32\n',
				'./bin/startup.sh'].join(''));
		} else if($(this).val() == '<%=PrjInfoContainer.LINUX_CUST.getCode()%>') {
			//类型为自定义服务
			_shellScript.val(['cd /app/appsoft/',code,'-1.0.0\n',
								'./bin/stop.sh\n',
								'mv /app/appsoft/',code,'-1.0.0/logs/stdout.out /app/appsoft/',code,'-1.0.0/logs/stdout_[current.time].out\n',
								'cp [prj.path][prj.name] /app/appsoft/',code,'-1.0.0\n',
								'rm -rf /app/appsoft/',code,'-1.0.0/',code,'-1.0.0.jar\n',
								'mv /app/appsoft/',code,'-1.0.0/[prj.name] /app/appsoft/',code,'-1.0.0/',code,'-1.0.0.jar\n',
								'./bin/start.sh'].join(''));
			stopScript.val(['cd /app/appsoft/',code,'-1.0.0\n',
				'./bin/stop.sh\n',
				'mv /app/appsoft/',code,'-1.0.0/logs/stdout.out /app/appsoft/',code,'-1.0.0/logs/stdout_[current.time].out'].join(''));
			restartScript.val(['cd /app/appsoft/',code,'-1.0.0\n',
				'./bin/stop.sh\n',
				'mv /app/appsoft/',code,'-1.0.0/logs/stdout.out /app/appsoft/',code,'-1.0.0/logs/stdout_[current.time].out\n',
				'cd /app/appsoft/',code,'-1.0.0\n',
				'./bin/start.sh'].join(''));
		} else if($(this).val() == '<%=PrjInfoContainer.WIN_TOMCAT.getCode()%>') {
			//类型为tomcat
			_shellScript.val(['E:\n',
			        'cd soft\\apache-tomcat-7.0.68\\bin\n',
					'start shutdown.bat\n',
					'choice /t 3 /d y /n >nul\n',	//延迟3秒
					'copy [prj.path][prj.name] E:\\soft\\apache-tomcat-7.0.68\\webapps\n',
					'del E:\\soft\\apache-tomcat-7.0.68\\webapps\\test.rar\n',
					'del /F /S /Q E:\\soft\\apache-tomcat-7.0.68\\webapps\\test\n',
					'rename E:\\soft\\apache-tomcat-7.0.68\\webapps\\[prj.name] test.rar\n',
					'cd E:\\soft\\apache-tomcat-7.0.68\\webapps\n',
					'unrar x -t -o-p E:\\soft\\apache-tomcat-7.0.68\\webapps\\test.rar E:\\soft\\apache-tomcat-7.0.68\\webapps\n',
					'choice /t 5 /d y /n >nul\n',	//延迟5秒
					'cd E:\\soft\\apache-tomcat-7.0.68\\bin\n',
					'start startup.bat'].join(''));
			stopScript.val(['E:\n',
		        'cd soft\\apache-tomcat-7.0.68\\bin\n',
				'start shutdown.bat'].join(''));
			restartScript.val(['E:\n',
		        'cd soft\\apache-tomcat-7.0.68\\bin\n',
				'start shutdown.bat\n',
				'cd E:\\soft\\apache-tomcat-7.0.68\\bin\n',
				'start startup.bat'].join(''));
		} else if($(this).val() == '<%=PrjInfoContainer.WIN_CUST.getCode()%>') {
			//类型为自定义
			_shellScript.val(['@echo off & setlocal enabledelayedexpansion\n',
					'echo Starting ...\n',
					'java -Xms256m -Xmx256m -XX:MaxPermSize=64M -jar ../../project.restful-1.0.0.jar\n',
					':end\n',
					'pause'].join(''));
		} else {
			_shellScript.val('');
		}
	});
});
</script>
</body>
</html>